#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

// 1.计算两个日期时间的差
void Widget::on_pushButton_clicked()
{
    QDateTime datetime1 = ui->dateTime_old->dateTime();
    QDateTime datetime2 = ui->dateTime_new->dateTime();

    int days = datetime1.daysTo(datetime2);
    int hours = ((datetime1.secsTo(datetime2)) / 3600) % 24;

    QString text = "日期相差：" + QString::number(days) + "天 " + QString::number(hours) + "小时";

    ui->label->setText(text);

}
